/*
 * @Description:
 * @Autor: GuluGuluu
 * @Date: 2023-06-24 13:20:16
 * @LastEditors: GuluGuluu
 * @LastEditTime: 2023-07-02 16:32:46
 */
import { Routes, Route, Navigate } from "react-router";
import MyNavLink from "./components/MyNavlink";
import { Button } from "amis-ui";
import { useAuth } from "./context/auth-context";
import Analyze from "./pages/Analyze";
import Login from "./pages/Login";
import UserManage from "./pages/UserManage";
import QuestionManage from "./pages/QuestionManage";
import TeacherManage from "./pages/UserManage/TeacherManage";
import AutoPaper from "./pages/AutoPaper";
import ManualPaper from "./pages/ManualPaper";
import StudentManage from "./pages/UserManage/StudentManage";
import QuestionSelect from "./pages/ManualPaper/QuestionSelect";
import ScoreSet from "./pages/ManualPaper/ScoreSet";
import QuestionNature from "./pages/QuestionNature";
import "./App.css";

function AuthenticatedApp() {
  const { logout } = useAuth();
  const { user } = useAuth();
  return (
    <div className="App">
      <header>
        <p className="nav-title">在线学习系统</p>
        <div className="nav-box">
          <MyNavLink
            className="link"
            active="link-active"
            path={"/analyze"}
            text="考试分析"
          ></MyNavLink>
          {user.type === "admin" && (
            <MyNavLink
              className="link"
              active="link-active"
              path={"/userManage"}
              text="用户管理"
            ></MyNavLink>
          )}
          {user.type !== "student" && (
            <>
              <MyNavLink
                className="link"
                active="link-active"
                path={"/manualPaper"}
                text="手动组卷"
              ></MyNavLink>
              <MyNavLink
                className="link"
                active="link-active"
                path={"/questionManage"}
                text="题目管理"
              ></MyNavLink>
              <MyNavLink
                className="link"
                active="link-active"
                path={"/questionNature"}
                text="题目性质"
              ></MyNavLink>
              <MyNavLink
                className="link"
                active="link-active"
                path={"/autoPaper"}
                text="自动组卷"
              ></MyNavLink>
            </>
          )}

          {/* 这里添加 MyNavLink 跳转按钮，path对应下面Route的path */}
          <Button
            onClick={logout}
            type="button"
            level="link"
            className="nav-btn"
          >
            注销
          </Button>
        </div>
      </header>
      <div className="content">
        <Routes>
          {/* 这里添加页面，path是地址栏体现的路径，element就是页面，按格式写就行 */}
          <Route path={"/analyze"} element={<Analyze />} />
          <Route path={"/login"} element={<Login />} />
          <Route path={"/questionManage"} element={<QuestionManage />} />
          <Route path={"/questionNature"} element={<QuestionNature />} />
          <Route path={"/manualPaper"} element={<ManualPaper />} />
          <Route path={"/manualPaper"} element={<ManualPaper />}>
            <Route
              path={"/manualPaper/questionSelect"}
              element={<QuestionSelect />}
            />
            <Route path={"/manualPaper/scoreSet"} element={<ScoreSet />} />
            <Route
              path={"/manualPaper"}
              element={<Navigate to="/manualPaper/questionSelect" />}
            />
          </Route>
          <Route path={"/userManage"} element={<UserManage />}>
            <Route
              path={"/userManage/teacherManage"}
              element={<TeacherManage />}
            />
            <Route
              path={"/userManage/studentManage"}
              element={<StudentManage />}
            />
            {/* <Route path={"studentManage"} element={<Login />} /> */}
            <Route
              path={"/userManage"}
              element={<Navigate to="/userManage/teacherManage" />}
            />
          </Route>
          <Route path={"/autoPaper"} element={<AutoPaper />}></Route>
          <Route path={"/"} element={<Navigate to="/analyze" />} />
        </Routes>
      </div>
    </div>
  );
}

export default AuthenticatedApp;
